﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
namespace Lawyer.Web.CustomInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					string CustomID= Request.Params["id"];
					ShowInfo(CustomID);
				}
			}
		}
			
	private void ShowInfo(string CustomID)
	{
		Lawyer.BLL.CustomInfo bll=new Lawyer.BLL.CustomInfo();
		Lawyer.Model.CustomInfo model=bll.GetModel(CustomID);
		this.lblCustomID.Text=model.CustomID;
		this.txtFullName.Text=model.FullName;
		this.txtEmail.Text=model.Email;
		this.txtSex.Text=model.Sex;
		this.txtBirthday.Text=model.Birthday.ToString();
		this.txtCity.Text=model.City;
		this.txtTelphone.Text=model.Telphone;
		this.txtFax.Text=model.Fax;
		this.txtAddress.Text=model.Address;
		this.txtAvatarURL.Text=model.AvatarURL;
		this.txtStatus.Text=model.Status.ToString();
		this.txtCreatedBy.Text=model.CreatedBy;
		this.txtCreatedDate.Text=model.CreatedDate.ToString();
		this.txtUpdatedBy.Text=model.UpdatedBy;
		this.txtUpdatedDate.Text=model.UpdatedDate.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtFullName.Text.Trim().Length==0)
			{
				strErr+="FullName不能为空！\\n";	
			}
			if(this.txtEmail.Text.Trim().Length==0)
			{
				strErr+="Email不能为空！\\n";	
			}
			if(this.txtSex.Text.Trim().Length==0)
			{
				strErr+="Sex不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtBirthday.Text))
			{
				strErr+="Birthday格式错误！\\n";	
			}
			if(this.txtCity.Text.Trim().Length==0)
			{
				strErr+="City不能为空！\\n";	
			}
			if(this.txtTelphone.Text.Trim().Length==0)
			{
				strErr+="Telphone不能为空！\\n";	
			}
			if(this.txtFax.Text.Trim().Length==0)
			{
				strErr+="Fax不能为空！\\n";	
			}
			if(this.txtAddress.Text.Trim().Length==0)
			{
				strErr+="Address不能为空！\\n";	
			}
			if(this.txtAvatarURL.Text.Trim().Length==0)
			{
				strErr+="AvatarURL不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtStatus.Text))
			{
				strErr+="Status格式错误！\\n";	
			}
			if(this.txtCreatedBy.Text.Trim().Length==0)
			{
				strErr+="CreatedBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCreatedDate.Text))
			{
				strErr+="CreatedDate格式错误！\\n";	
			}
			if(this.txtUpdatedBy.Text.Trim().Length==0)
			{
				strErr+="UpdatedBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtUpdatedDate.Text))
			{
				strErr+="UpdatedDate格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string CustomID=this.lblCustomID.Text;
			string FullName=this.txtFullName.Text;
			string Email=this.txtEmail.Text;
			string Sex=this.txtSex.Text;
			DateTime Birthday=DateTime.Parse(this.txtBirthday.Text);
			string City=this.txtCity.Text;
			string Telphone=this.txtTelphone.Text;
			string Fax=this.txtFax.Text;
			string Address=this.txtAddress.Text;
			string AvatarURL=this.txtAvatarURL.Text;
			int Status=int.Parse(this.txtStatus.Text);
			string CreatedBy=this.txtCreatedBy.Text;
			DateTime CreatedDate=DateTime.Parse(this.txtCreatedDate.Text);
			string UpdatedBy=this.txtUpdatedBy.Text;
			DateTime UpdatedDate=DateTime.Parse(this.txtUpdatedDate.Text);


			Lawyer.Model.CustomInfo model=new Lawyer.Model.CustomInfo();
			model.CustomID=CustomID;
			model.FullName=FullName;
			model.Email=Email;
			model.Sex=Sex;
			model.Birthday=Birthday;
			model.City=City;
			model.Telphone=Telphone;
			model.Fax=Fax;
			model.Address=Address;
			model.AvatarURL=AvatarURL;
			model.Status=Status;
			model.CreatedBy=CreatedBy;
			model.CreatedDate=CreatedDate;
			model.UpdatedBy=UpdatedBy;
			model.UpdatedDate=UpdatedDate;

			Lawyer.BLL.CustomInfo bll=new Lawyer.BLL.CustomInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
